package com.itheima.mall.controller.smsController;


import com.itheima.mall.commons.R;
import com.itheima.mall.service.smsService.SmsHomeAdvertiseService;
import com.itheima.pojo.sms.SmsHomeAdvertise;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/home")
@CrossOrigin
public class SmsHomeAdvertiseController {
    @Autowired
    private SmsHomeAdvertiseService smsHomeAdvertiseService;
    /**
     * 添加广告
     * advertise
     */
    @PostMapping("/advertise/create")
    public R create(@RequestBody SmsHomeAdvertise advertise) {
        return smsHomeAdvertiseService.create(advertise);
    }

    /**
     * 删除广告  ids
     */
    @PostMapping("/advertise/delete")
    public R delete(@RequestParam("ids") List<Long> ids) {
        return smsHomeAdvertiseService.delete(ids);
    }

    /**
     * 分页查询广告
     * endTime name pageNum pageSize type
     */
    @GetMapping("/advertise/list")
    public R list(@RequestParam(value = "endTime", required = false) String endTime,
                  @RequestParam(value = "name", required = false) String name,
                  @RequestParam(value = "pageNum", required = false) Integer pageNum,
                  @RequestParam(value = "pageSize", required = false) Integer pageSize,
                  @RequestParam(value = "type", required = false) Integer type) {
        return smsHomeAdvertiseService.list(endTime, name, pageNum, pageSize, type);
    }

    /**
     * 修改上下线状态
     * id  status
     */
    @PostMapping("/advertise/update/status/{id}")
    public R updateStatus(@PathVariable Long id, @RequestParam("status") Integer status) {
        return smsHomeAdvertiseService.updateStatus(id, status);
    }

    /**
     * 修改广告
     * id smsHomeAdvertise
     */
    @PostMapping("/advertise/update/{id}")
    public R updateById(@PathVariable Long id, @RequestBody SmsHomeAdvertise smsHomeAdvertise) {
        return smsHomeAdvertiseService.updateById(id, smsHomeAdvertise);
    }

    /**
     * 获取广告详情
     * id
     */
    @GetMapping("/advertise/{id}")
    public R getAdvertiseById(@PathVariable Long id) {
        return smsHomeAdvertiseService.getAdvertiseById(id);
    }

}
